package com.jlc.book.shop.tags;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

import org.apache.log4j.Logger;

public class ValidateSessionTag extends TagSupport {
	
	
	Logger log=Logger.getLogger(this.getClass());
	
	@Override
	public int doEndTag() throws JspException {
		
		try
		{
			HttpServletRequest request=(HttpServletRequest) pageContext.getRequest();
			HttpServletResponse response=(HttpServletResponse)pageContext.getResponse();
			if(request.getSession().getAttribute("USER_TO")==null)
			{
				request.setAttribute("loginError", "Session timeout.Please login again");
				request.getRequestDispatcher("index.jsp").forward(request, response);
			}
		}
		catch (Exception e) {
			
			log.error("Exception in ValidateSession Tag\n",e);
			
		}
		return EVAL_PAGE;
	}
	

}
